package com.kele.utils;//package com.two.domain;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;

/**
// * @author 赵奥林
// * @date 2021年05月20日 17:03
// * @Description  自定义的返回数据类
// */
@Data
@NoArgsConstructor
@ToString
@ApiModel(description = "返回响应数据")
public class ResponseData<T> implements Serializable {

     //状态码：0-成功，1-失败
    @ApiModelProperty(value = "状态码")
    private int code;


    //错误消息，如果成功可为空或SUCCESS
    @ApiModelProperty(value = "错误信息")
    private String msg;


     //返回结果数据
    @ApiModelProperty(value = "返回数据对象")
    private T data;


    public static ResponseData success(String msg) {
        return success(msg,null);
    }

    public static ResponseData success(String msg,Object data) {
        ResponseData result = new ResponseData();
        result.setCode(0);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static ResponseData fail(String msg) {
        ResponseData result=new ResponseData();
        result.setCode(1);
        result.setMsg(msg);
        return result;
    }

    public static ResponseData fail(String msg, Object data) {
        ResponseData result = new ResponseData();
        result.setCode(1);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
}